#include <stdio.h>
#include <stdlib.h>

//共用体
union perdata
{
    int class;
    char *office;
} a, b;
/*
共用体的定义和变量申明和结构体类似
区别在于，不同的结构体变量占用不同的存储空间，而不同的共用体占用相同的存储空间
*/

int main()
{
    printf("\n\n========================================================================\n\n");
    struct
    {
        char *name;
        int age;
        char job;
        union
        {
            int class;
            char *office;
        } depa;

    } body[2];
    body[0].name = "张三";
    body[0].age = 20;
    body[0].depa.class = 2;
    body[0].depa.office = "教师";
    body[1].name = "李四";
    body[1].age = 22;
    body[1].depa.class = 3;
    body[1].depa.office = "主任";
    printf("body1--name=%s,age=%d,depa.class=%d,depa.office=%s\n", body[0].name, body[0].age, body[0].depa.class, body[0].depa.office);
    printf("body2--name=%s,age=%d,depa.class=%d,depa.office=%s\n", body[1].name, body[1].age, body[1].depa.class, body[1].depa.office);

    printf("body1=%d\n", &(body[0].depa));
    printf("body1=%d\n", &(body[0].depa));
    printf("\n\n========================================================================\n\n");
    return 0;
}